; burglar domain:
; Csaba Toth

(define (domain burglar)
	(:requirements :strips :typing :adl :preferences)		; for sgplan
	;(:requirements :strips :typing)						; for lpg planner
	;(:requirements :strips :typing :adl)					; for metricff
	
	(:types
		t_burglar t_dog t_guard											- t_agent
		t_key t_treasure												- t_item
		t_agent t_container												- t_inventory
		t_container t_door												- t_lockable
		t_phone t_vender												- t_operable
		t_camera t_container t_phone t_switch t_vender t_door t_floor	- t_position
		t_room															- t_room
	)
	
	(:predicates
		(closed ?position - t_lockable)									; a lockable position is closed
		(locked ?position - t_lockable)									; a lockable position is locked
		(needs_key ?lockable - t_lockable ?key - t_key)					; the key needed to unlock the lockable position
		(agent_next_to ?agent - t_agent ?position - t_position)			; the agent stands next to the position
		(agent_in ?agent - t_agent ?room - t_room)						; the agent is in the room
		(position_in ?position - t_position ?room - t_room)				; the position is in the room
		(door_connects ?door - t_door ?room1 - t_room ?room2 - t_room)	; the door connects the two rooms together
		(contains ?inventory - t_inventory ?item - t_item)				; the container contains the item
		(empty ?container - t_container)								; the container contains no item (triggered by pick_all, but not by pick_from)
		(visited ?agent - t_agent ?room - t_room)						;
		
		
	)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; actions:
;;
;;;; move_to		- leaves a position and goes to another one in the same room
;;;; enter_door		- crosses the door to another room (visited is set to true)
;;;; open			- opens a lockable position
;;;; close			- closes a lockable position
;;;; unlock			- unlocks a lockable position
;;;; lock			- locks a lockable position
;;;; pick_from		- picks an item from a container
;;;; pick_all		- picks up anything that is in the container (not a real action, has to trigger replanning)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	(:action move_to
		:parameters
		(
			?agent		- t_agent
			?start		- t_position
			?aim		- t_position
			?room		- t_room
		)
		:precondition
		(and
			(agent_in ?agent ?room)
			(position_in ?aim ?room)
			(agent_next_to ?agent ?start)
			(not (agent_next_to ?agent ?aim))
		)
		:effect
		(and
			(agent_next_to ?agent ?aim)
			(not (agent_next_to ?agent ?start))
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action enter_door
		:parameters
		(
			?agent		- t_agent
			?door		- t_door
			?room_from	- t_room
			?room_to	- t_room
		)
		:precondition
		(and
			(agent_in ?agent ?room_from)
			(door_connects ?door ?room_from ?room_to)
			(agent_next_to ?agent ?door)
			(not (closed ?door))
		)
		:effect
		(and
			(agent_in ?agent ?room_to)
			(not (agent_in ?agent ?room_from))
			(visited ?agent ?room_to)
			(visited ?agent ?room_from)
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action open
		:parameters
		(
			?agent		- t_agent
			?lockable	- t_lockable
		)
		:precondition
		(and
			(agent_next_to ?agent ?lockable)
			(closed ?lockable)
			(not(locked ?lockable))
		)
		:effect
		(and
			(not (closed ?lockable))
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action close
		:parameters
		(
			?agent		- t_agent
			?lockable	- t_lockable
		)
		:precondition
		(and
			(agent_next_to ?agent ?lockable)
			(not (closed ?lockable))
		)
		:effect
		(and
			(closed ?lockable)
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action unlock
		:parameters
		(
			?agent		- t_agent
			?lockable	- t_lockable
			?key		- t_key
		)
		:precondition
		(and
			(agent_next_to ?agent ?lockable)
			(locked ?lockable)
			(contains ?agent ?key)
			(needs_key ?lockable ?key)
		)
		:effect
		(and
			(not (locked ?lockable))
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action lock
		:parameters
		(
			?agent		- t_agent
			?lockable	- t_lockable
			?key		- t_key
		)
		:precondition
		(and
			(agent_next_to ?agent ?lockable)
			(not (locked ?lockable))
			(contains ?agent ?key)
			(needs_key ?lockable ?key)
		)
		:effect
		(and
			(locked ?lockable)
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action pick_from
		:parameters
		(
			?agent		- t_agent
			?container	- t_container
			?item		- t_item
		)
		:precondition
		(and
			(agent_next_to ?agent ?container)
			(not (closed ?container))
			(contains ?container ?item)
		)
		:effect
		(and
			(not (contains ?container ?item))
			(contains ?agent ?item)
		)
	)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	(:action pick_all
		:parameters
		(
			?agent		- t_agent
			?container	- t_container
		)
		:precondition
		(and
			(agent_next_to ?agent ?container)
			(not (closed ?container))
		)
		:effect
		(and
			(empty ?container)
		)
	)
)

